#@head() #@header()
<title>消息通知</title>
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
#@aside("marketing")
<div class="content-wrapper">
	<section class="content">
		<div class="nav-tabs-custom">
             #@appmenu("appmessage")
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="tab_1">
				 <button type="button" onclick="window.location.href='#(path)/admin/page/marketing-addnews?type=notice'" class="btn btn-block btn-info" style="width:120px;float:left;margin-top:10px;margin-right:20px;">新建消息推送</button>
				<div class="box-body">
					<table id="example1" class="table table-striped">
						<thead>
							<tr>
								<th>ID</th>
								<th>标题</th>
								<th>类型</th>
								<th>创建时间</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="newslist">
						</tbody>
					</table>
				</div>
				<div class="box-footer clearfix">
				  <ul class="pagination pagination-sm no-margin pull-right">
					<li id="newslist1"><a href="#">首页</a></li>
					<li id="newslist2"><a href="#">上一页</a></li>
					<li><a href="#">第<span id="newslist5"></span>页 共<span id="newslist6"></span>页</a></li>
					<li id="newslist3"><a href="#">下一页</a></li>
					<li id="newslist4"><a href="#">尾页</a></li>
				  </ul>
				</div>
              </div>
            </div>
            <!-- /.tab-content -->
          </div>
		  
	</section>
</div>
#@footer()
<script id="newslistall" type="text/x-jquery-tmpl">
	<tr>
		<td>${id}</td>
		<td>${name}</td>
		<td>${type}</td>
		<td>${create_time}</td>
		<td>${status}</td>
		<td>
			<div class="btn-group">
			  <div class="btn-group">
			  <button onclick="window.location.href='#(path)/admin/page/marketing-changenews?id=${id}&obj=appmessage'" type="button" class="btn btn-info">修改</button>
			   <button pass="${id}" type="button" class="btn btn-warning pass">${status2}</button>
			   <button pass="${id}" type="button" class="btn btn-danger del">删除</button>
			</div>
			</div>
		</td>
	</tr>
</script>
<script>
var totalPage = 1;
var pageNumber = 1;
 $(document).ready(function(){
	totalPage = 1;
	pageNumber = 1;
	$("#newslist").empty();
	newslist(1);
	$("#newslist5").html(pageNumber);
});
$("#newslist1").click(function(){
	$("#newslist").empty();
	newslist(1);
	pageNumber = 1;
	$("#newslist5").html(pageNumber);
});
$("#newslist2").click(function(){
	if(pageNumber==1){
		alert("当前页是首页!");
	}else{
	$("#newslist").empty();
	pageNumber = pageNumber-1;
	newslist(pageNumber);
	$("#newslist5").html(pageNumber);
	}
});
$("#newslist3").click(function(){
	if(pageNumber==totalPage){
		alert("当前页是尾页!");
	}else{
	$("#newslist").empty();
	pageNumber = pageNumber +1;
	newslist(pageNumber);
	$("#newslist5").html(pageNumber);
	}
});
$("#newslist4").click(function(){
	$("#newslist").empty();
	newslist(totalPage);
	pageNumber = totalPage;
	$("#newslist5").html(pageNumber);
});
function newslist(page){
	$.getJSON("/notice/list?type=notice&token=#(session.token??)&page="+page+"&size=12", function(userli) {
		 
		totalPage = userli.data.page.totalPage;
		$("#newslist6").html(totalPage);
		$.each(userli.data.page.list, function(i, item){ 
			if(item.status=="disable"){
				var status = "下线";
				var status2 = "上线";
			}else{
				var status = "上线";
				var status2 = "下线";
			}
			var type = "通知消息";
			if(item.type=="activity"){
				type = "活动精选";
			}else if(item.type=="news"){
				type = "新闻公告";  
			}
			var newslist = {type:type,name:item.name,status:status,id:item.id,create_time:item.create_time,status2:status2};
			$("#newslistall").tmpl(newslist).appendTo('#newslist');
		});
		$(".pass").click(function(){
			var idval = $(this).attr("pass");
			var bb="";
			var aa=$(this).html();
			 
			if(aa=="上线"){ bb = "enable"}else if(aa=="下线"){ bb = "disable"}
			 
			$.getJSON("/notice/switchStatus?token=#(session.token??)&id="+idval+"&status="+bb, function(data) {
				if(data.code=='success'){
					layer.msg(data.msg, {icon:1},function(){
						location.href="#(path)/admin/page/marketing-appnews"
					});
				}else if(data.code=='error'){
					layer.msg(data.msg, {icon:2});
				}
			});
		});
		$(".del").click(function(){
			var idval = $(this).attr("pass");
			layer.confirm('确定要删除吗？', {
			  btn: ['十分确定','取消'] //按钮
			}, function(){
				$.getJSON("/notice/del?token=#(session.token??)&id="+idval, function(data) {
					if(data.code=='success'){
						layer.msg(data.msg, {icon:1},function(){
							location.href="#(path)/admin/page/marketing-appmessage"
						});
					}else if(data.code=='error'){
						layer.msg(data.msg, {icon:2});
					}
				});
			});
		});
	});	
}
</script> 

</body>
</html>

